package com.kmproject.haifu.mvp.ui.holder;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.integration.AppManager;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.ui.adapter.PopuWindowSelectZjAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ZjSelectHolder {

    @BindView(R.id.popuwindows_seelct_zj_zdj)
    EditText popuwindowsSeelctZjZdj;
    @BindView(R.id.popuwindows_seelct_zj_zgj)
    EditText popuwindowsSeelctZjZgj;
    @BindView(R.id.popuwindows_seelct_zj_btn)
    TextView popuwindowsSeelctZjBtn;
    PriceCallback mpriceCallback;
    @BindView(R.id.popuwindows_seelct_zj_RecyclerView)
    RecyclerView popuwindowsSeelctZjRecyclerView;

    public ZjSelectHolder(Activity activity,List<HousePayWayBean> housePayWayBeans, View view, PriceCallback priceCallback) {
//        R.layout.popuwindows_seelct_zj
        ButterKnife.bind(this, view);
        mpriceCallback = priceCallback;
        HousePayWayBean housePayWayBean=new HousePayWayBean("不限");
        housePayWayBean.setName("不限");
        housePayWayBeans.add(0,housePayWayBean);
        popuwindowsSeelctZjRecyclerView.setLayoutManager(new LinearLayoutManager(activity));
        PopuWindowSelectZjAdapter adapter=new PopuWindowSelectZjAdapter(housePayWayBeans);
        popuwindowsSeelctZjRecyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter madapter, View view, int position) {
                if (position==0)
                {
                    popuwindowsSeelctZjZdj.setText("");
                    popuwindowsSeelctZjZgj.setText("");
                }else {
                    //code 最大   cage 最小
                    popuwindowsSeelctZjZdj.setText(adapter.getData().get(position).getCategory());
                    popuwindowsSeelctZjZgj.setText(adapter.getData().get(position).getCode());
                }
                mpriceCallback.callBack(popuwindowsSeelctZjZdj.getText().toString(), popuwindowsSeelctZjZgj.getText().toString());
            }
        });
    }

    @OnClick(R.id.popuwindows_seelct_zj_btn)
    public void onClick() {
        if (popuwindowsSeelctZjZdj.getText().toString().length() < 1) {
            ArmsUtils.makeText(AppManager.getAppManager().getCurrentActivity(), "请输入最低价格");
            return;
        }
        if (popuwindowsSeelctZjZgj.getText().toString().length() < 1) {
            ArmsUtils.makeText(AppManager.getAppManager().getCurrentActivity(), "请输入最高价格");
            return;
        }
        mpriceCallback.callBack(popuwindowsSeelctZjZdj.getText().toString(), popuwindowsSeelctZjZgj.getText().toString());
    }

    public interface PriceCallback {
        void callBack(String samllPrice, String bigPrice);
    }
}
